<template>
  <div class="patient-transfer">
    <el-card>
      <div slot="header" class="clearfix">
        <span>患者列表</span>
      </div>
      <el-table :data="crud.selections" style="width: 100%">
        <el-table-column prop="id" label="患者编号" width="180">
        </el-table-column>
        <el-table-column prop="patientName" label="患者姓名" width="120">
        </el-table-column>
        <el-table-column prop="doctorName" label="主治医生" width="120">
        </el-table-column>
        <el-table-column prop="clinicName" label="诊所名称"> </el-table-column>
      </el-table>
    </el-card>
    <div class="transfer">
      <img src="@/assets/icons/patient/transfer.png" alt="" />
    </div>
    <el-card>
      <div slot="header" class="clearfix">
        <span>转移至诊所/医生</span>
        <el-input
          v-model="params.searchName"
          type="text"
          placeholder="诊所名称/医生名称"
          @change="queryList"
        ></el-input>
      </div>
      <el-table
        ref="table"
        v-loading="loading"
        stripe
        :data="data"
        size="small"
        style="width: 100%"
        @current-change="handleTable"
      >
        <el-table-column width="35">
          <template slot-scope="scope">
            <el-radio v-model="tempRadio" :label="scope.row.id"></el-radio>
          </template>
        </el-table-column>
        <el-table-column prop="clinicName" label="诊所名称"> </el-table-column>
        <el-table-column prop="doctorName" label="医生姓名"> </el-table-column>
      </el-table>
      <el-pagination
        :current-page="params.page"
        :page-sizes="[10, 20, 30, 40, 50, 100]"
        :page-size="params.size"
        layout="total, prev, pager, next, sizes"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </el-card>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="transferSubmit">确认</el-button>
      <el-button type="text" @click="close">取消</el-button>
    </div>
  </div>
</template>
<script>
import { queryDoctor, queryPatient } from '@/api/operPatient';
import CRUD, { crud } from '@crud/crud';
export default {
  mixins: [crud()],
  data() {
    return {
      params: {
        page: 0,
        size: 10,
        sort: ['id,desc'],
        searchName: ''
      },
      total: 0,
      data: [],
      multipleSelection: [],
      loading: false,
      tempRadio: ''
    };
  },
  mounted() {
    this.queryList();
  },
  methods: {
    queryList() {
      this.loading = true;
      // 请求数据
      queryDoctor('queryBindingTab', this.params)
        .then((data) => {
          this.total = data.totalElements;
          this.data = data.content;
          this.loading = false;
        })
        .catch((err) => {
          this.total = 0;
          this.loading = false;
          reject(err);
        });
    },
    handleSizeChange(val) {
      this.params.size = val;
      this.queryList();
    },
    handleCurrentChange(val) {
      this.params.page = val - 1;
      this.queryList();
    },
    close() {
      this.$emit('closeDialog', true);
    },
    // 点击表格中每一行也能选中单选按钮,选择改行数据
    handleTable(row) {
      // 如果没有row,终止
      if (!row) return;
      // 把当前行label绑定的值和v-model绑定的值相同时,单选按钮就可以选中
      this.tempRadio = row.doctorId;
      this.multipleSelection = row;
    },
    transferSubmit() {
      const ids = this.crud.selections.map((item) => {
        return item.id;
      });
      if (this.tempRadio == '') {
        this.$message.error('请选择诊所/医生！');
        return;
      }
      const params = {
        doctorId: this.tempRadio,
        patientIds: ids
      };

      // queryPatient("transfer", JSON.stringify(params))
      //   .then((res) => {
      this.crud.submitSuccessNotify();
      this.close();
      //   })
      //   .catch((er) => {});
    }
  }
};
</script>
<style lang="scss">
.patient-transfer {
  .transfer {
    img {
      margin: 20px 358px;
      width: 42px;
      height: 42px;
    }
  }
  .el-card__header {
    border: none;
    padding-bottom: 0px;
    .clearfix {
      line-height: 32px;
    }
    .el-input {
      float: right;
      width: 200px;
    }
  }
  .dialog-footer {
    overflow: hidden;
    margin-top: 20px;
  }
  .dialog-footer button {
    float: right;
  }
}
</style>
